<%@page import="com.lowagie.text.Cell"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/classes/DBHelper.class.jsp"%>
<%@ include file="/classes/CommonHelper.class.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("basePath", basePath);
%>

<%
	//获取数据
	String time1 = getParameter(request, "time1");
	String time2 = getParameter(request, "time2");
	long startYear = toDate("yyyy", fotmatNewTime("yyyy")).getTime()- 8 * 60 * 60 * 1000;//今年开始时间
	String sql = "select T1.CREATOR_ID, T2.NAME,count(*) as total , sum(case when t1.STATUS = '4' then 1 else 0 end) as cy ,sum(case when (t1.STATUS = '4' and t1.PUBLISHED_TIME >= "+startYear+")  then 1 else 0 end) as cy2     from CMS_MANUSCRIPT t1,CMS_USER t2,CMS_WEBSITE t3 where  t1.CREATOR_ID = T2.USER_ID and T1.WEBSITE_ID = T3.WEBSITE_ID and (T3.WEBSITE_ID = '83ae5ea8ee404ab2b575dc84f49e8319' or T3.PARENT_WEBSITE_ID = '528114e8e9f04c6d95193a2ac2ffdef8') ";
	List<Object> params = new ArrayList<Object>();
	if (!nullOrEmpty(time1)) {
		try {
			long time = toDate("yyyy-MM-dd HH:mm:ss", time1).getTime();
			sql += " and t1.PUBLISHED_TIME >= ?";
			params.add(time - 8 * 60 * 60 * 1000);//减去8小时
			pageContext.setAttribute("time1", time1);
		} catch (Exception e) {
		}
	}
	if (!nullOrEmpty(time2)) {
		try {
			long time = toDate("yyyy-MM-dd HH:mm:ss", time2).getTime();
			sql += " and t1.PUBLISHED_TIME <= ? ";
			params.add(time - 8 * 60 * 60 * 1000);//减去8小时
			pageContext.setAttribute("time2", time2);
		} catch (Exception e) {
		}
	}
	sql += " group by T1.CREATOR_ID,T2.NAME order by total desc";
	List<Map<String, Object>> list = queryForList(sql, params);
	pageContext.setAttribute("list", list);
%>
<!DOCTYPE html>
<html>
<head>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>睢宁人大信息报送统计</title>

<script type='text/javascript'
	src="${basePath }plugins/jquery/jquery-1.12.2.min.js"></script>
<link rel="stylesheet"
	href="${basePath }plugins/layui/v1.0.9/css/layui.css" media="all">
<style type="text/css">
.question, .answer {
	overflow: hidden;
	width: 350px;
	display: inline-block;
	text-overflow: ellipsis;
	white-space: nowrap;
}
</style>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title"
		style="margin: 5px auto 5px auto">
		<legend style="color: red">睢宁人大信息报送统计</legend>
	</fieldset>
	<form class="layui-form" action="" method="post">
		<input type="hidden" id="r" value="<%=System.currentTimeMillis()%>">
		<div class="layui-form-item" style="margin-bottom: 0px;">
			<div class="layui-inline">
				<label class="layui-form-label">时间范围</label>
				<div class="layui-input-inline" style="width: 170px;">
					<input type="text" id="time1" name="time1" value="${time1 }"
						readonly="readonly" autocomplete="off" class="layui-input"
						onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'time2\')}'})"
						placeholder="请选择开始时间">
				</div>
				<div class="layui-form-mid">-</div>
				<div class="layui-input-inline" style="width: 170px;">
					<input type="text" id="time2" name="time2" value="${time2 }"
						readonly="readonly" autocomplete="off" class="layui-input"
						onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'time1\')}'})"
						placeholder="请选择结束时间">
				</div>
			</div>
			<div class="layui-inline">
				<button class="layui-btn layui-btn-primary" id="searchBtn">
					<i class="layui-icon">&#xe615;</i> 查询
				</button>
			</div>
		</div>
		<table class="layui-table">
			<thead>
				<tr>
					<th>用户名</th>
					<th>报送稿件数量</th> 
					<th>采用稿件数量</th>
					<c:if test="${empty time1 && empty time2  }">
					<th>今年采用稿件数量</th>
					</c:if>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${list }" var="s">
					<tr>
						<td>${s.name }</td>
						<td>${s.total }</td>
						<td>${s.cy }</td>
						<c:if test="${empty time1 && empty time2  }">
						<td>${s.cy2 }</td>
						</c:if>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</form>
	<script type="text/javascript"
		src="${basePath }plugins/layui/v1.0.9/layui.js"></script>
	<script charset="utf-8"
		src="${basePath }plugins/97date/4.8/WdatePicker.js"></script>
	<script type='text/javascript'>
		layui.use('form', function() {
			var $ = layui.jquery, form = layui.form();

			//全选
			form.on('checkbox(allChoose)', function(data) {
				var child = $(data.elem).parents('table').find(
						'tbody input[type="checkbox"]');
				child.each(function(index, item) {
					item.checked = data.elem.checked;
				});
				form.render('checkbox');
			});

		});
	</script>
</body>
</html>